package com.xoms.admin.persist.impl;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xoms.admin.model.ProPriceBean;
import com.xoms.admin.persist.dao.ProPriceDao;
import com.xoms.util.StringUtil;

@Repository
public class ProPriceImpl extends BaseImpl implements ProPriceDao {
	
	final String NAME_SPACE = NAME_SPACE_HEADER + ".ProPriceMapper";

	@Override
	public int selectCount(String key, String productId) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}
		if (!StringUtil.isEmpty(productId)) {
			params.put("productId", productId);
		}
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", params);
	
	}

	@Override
	public List<ProPriceBean> selectList(String key, String productId, int page, int pagesize) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("start", page * pagesize);
		params.put("length", pagesize);
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}
		if (!StringUtil.isEmpty(productId)) {
			params.put("productId", productId);
		}
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", params);

	}

	@Override
	public int insert(ProPriceBean data) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", data);
	}

	@Override
	public int update(ProPriceBean data) {
		return sqlSessionTemplate.update(NAME_SPACE + ".update", data);
	}

	@Override
	public ProPriceBean selectOneById(String pid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneById", pid);
	}

	@Override
	public int updateStatus(String pid, int status) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("pid", pid);
		params.put("status", status);
		return sqlSessionTemplate.update(NAME_SPACE + ".updateStatus", params);
	}

	@Override
	public Double selectProductPrice(String productId) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectProductPrice", productId);
	}

	@Override
	public int del(String pid) {
		return sqlSessionTemplate.delete(NAME_SPACE + ".delete", pid);
	}

	@Override
	public Timestamp selectLastEndTime(String productId) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectLastEndTime", productId);
	}



}
